package com.lz.ht.service.serviceImpl;

import com.lz.ht.dao.MemberDao;
import com.lz.ht.model.Member;
import com.lz.ht.model.Room;
import com.lz.ht.page.PageModel;
import com.lz.ht.service.MemberService;
import com.lz.ht.util.ToolKit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;

/**
 * @ClassName: MemberServiceImpl
 * @Description:
 * @Author: CHonghao
 * @Date: 2021/7/10 8:54
 * @Version: V1.0
 **/

@Service
@Transactional(rollbackFor = Exception.class)
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberDao memberDao;

    @Override
    public List<Member> findPageList(PageModel<Member> page, Member member) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(member);
        hashMap.put("msFirst", page.getMsFirst());
        hashMap.put("msLast", page.getMsLast());
        return memberDao.findListByMapLimit(hashMap);
    }

    @Override
    public long findCount(Member member) throws Exception {
        HashMap<String, Object> hashMap = ToolKit.javaBeanToMap(member);
        return memberDao.findCountByMap(hashMap);
    }

    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    @Override
    public Member findById(Integer mid) {
        return memberDao.selectByPrimaryKey(mid);
    }

    @Override
    public void updateById(Member member) {
        memberDao.updateByPrimaryKeySelective(member);
    }

    @Override
    public void deleteById(Integer mid) {
        memberDao.deleteByPrimaryKey(mid);
    }
}
